﻿# Demand Concubine
demand_concubine_interaction = {
	category = interaction_category_vassal
	common_interaction = yes
	icon = request_concubine_interaction
	interface_priority = 44

	desc = demand_concubine_interaction_desc

	cost = {
		prestige = {
			value = 0
			if = {
				limit = { 
					NAND = {
						scope:actor = {
							government_has_flag = government_has_influence 
						}
						scope:recipient = {
							government_has_flag = government_has_influence 
							is_vassal_or_below_of = scope:actor
						}
					}
				}
				add = {
					if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value >= 3
								}
							}
						}
						add = miniscule_prestige_value
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value = 2
								}
							}
						}
						add = minor_prestige_value	
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value = 1
								}
							}
						}
						add = 100	
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value = 0
								}
							}
						}
						add = medium_prestige_value
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value = -1
								}
							}
						}
						add = major_prestige_value
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value = -2
								}
							}
						}
						add = massive_prestige_value
					}
					else_if = {
						limit = {
							scope:actor = {
								tier_difference = {
									target = scope:recipient
									value <= -3
								}
							}
						}
						add = monumental_prestige_value
					}
				}
			}
		}
		influence = {
			value = 0
			if = {
				limit = { 
					scope:actor = {
						government_has_flag = government_has_influence 
						exists = house
					}
					scope:recipient = {
						government_has_flag = government_has_influence 
						is_vassal_or_below_of = scope:actor
						exists = house
						house = {	
							NOT = { this = scope:actor.house }
						}
					}
				}
				add = {
					if = { # Demanding to the Imperial Family
						limit = {
							scope:recipient.house = {
								any_house_member = {
									is_independent_ruler = yes
									government_has_flag = government_has_influence 
									any_vassal_or_below = {
										OR = {
											this = scope:actor
											this = scope:recipient
										}
									}
								}
							}
						}
						add = monumental_influence_value
					}
					else_if = {
						limit = {
							scope:recipient.house = {
								is_dominant_family = yes
							}
						}
						add = massive_influence_value
					}
					else_if = {
						limit = {
							scope:recipient.house = {
								is_powerful_family = yes
							}
						}
						add = major_influence_value
					}
					else_if = {
						limit = {
							scope:actor = {
								house = {
									is_powerful_family = no
								}
							}
							scope:recipient.house = {
								is_powerful_family = no
							}
						}
						add = medium_influence_value
					}
					else = {
						add = minor_influence_value
					}
				}
			}
		}
		# gold = {
		# 	value = 0
		# 	if = {
		# 		limit = {
		# 			exists = scope:secondary_actor
		# 		}
		# 		value = minor_gold_value
		# 		if = { #Emperors and Kings will pay more
		# 			limit = {
		# 				scope:actor.primary_title.tier >= tier_kingdom
		# 			}
		# 			if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							OR = {
		# 								primary_title.tier >= tier_kingdom
		# 								is_councillor_of = scope:actor
		# 								is_powerful_vassal_of = scope:actor
		# 							}
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.50
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							primary_title.tier = tier_duchy
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.40
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.30
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						is_lowborn = no
		# 					}
		# 				}
		# 				multiply = 0.20
		# 			}
		# 			else = {
		# 				multiply = 0.10
		# 			}
		# 		}
				
		# 		if = { #Dukes
		# 			limit = {
		# 				scope:actor.primary_title.tier <= tier_duchy
		# 			}
		# 			if = { 
		# 				limit = { #If a Count has a Prince in their court, somehow.
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							primary_title.tier >= tier_kingdom
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.50
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							primary_title.tier = tier_duchy
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.40
		# 			}
		# 			if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							OR = {
		# 								is_councillor_of = scope:actor
		# 								is_powerful_vassal_of = scope:actor
		# 							}
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.30
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 							primary_title.tier = tier_county
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.20
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						any_close_family_member = {
		# 							is_landed_or_landless_administrative = yes
		# 						}
		# 					}
		# 				}
		# 				multiply = 0.15
		# 			}
		# 			else_if = { 
		# 				limit = {
		# 					scope:secondary_actor = {
		# 						is_lowborn = no
		# 					}
		# 				}
		# 				multiply = 0.10
		# 			}
		# 			else = {
		# 				multiply = 0.05
		# 			}
		# 		}
				
		# 		if = { #Councillors are expensive
		# 			limit = {
		# 				scope:secondary_actor = {
		# 					is_councillor = yes
		# 				}
		# 			}
		# 			multiply = 1.20
		# 		}
		# 		if = { #Knights too
		# 			limit = {
		# 				scope:secondary_actor = {
		# 					is_knight = yes
		# 				}
		# 			}
		# 			multiply = 1.10
		# 		}
		# 		if = { #And court positions
		# 			limit = {
		# 				scope:secondary_actor = {
		# 					has_any_court_position = yes
		# 				}
		# 			}
		# 			multiply = 1.10
		# 		}
				
		# 		if = { #Generous
		# 			limit = {
		# 				scope:actor = {
		# 					has_trait = generous
		# 				}
		# 			}
		# 			multiply = 1.25
		# 		}
		# 		if = { #Greedy
		# 			limit = {
		# 				scope:actor = {
		# 					has_trait = greedy
		# 				}
		# 			}
		# 			multiply = 0.65
		# 		}

		# 		#Inflation
		# 		if = {
		# 			limit = {
		# 				scope:actor.culture = {
		# 					has_cultural_era_or_later = culture_era_high_medieval
		# 				}
		# 			}
		# 			multiply = 1.20
		# 		}
		# 		if = {
		# 			limit = {
		# 				scope:actor.culture = {
		# 					has_cultural_era_or_later = culture_era_late_medieval
		# 				}
		# 			}
		# 			multiply = 1.20
		# 		}
		# 		ceiling = yes
		# 	}
		# }
	}

	ai_targets = {
		ai_recipients = tributaries
		ai_recipients = vassals
	}
	ai_target_quick_trigger = {
		adult = yes
	}
	ai_frequency = 12
	cooldown_against_recipient = { years = 3 }

	greeting = positive
	notification_text = DEMAND_CONCUBINE_NOTIFICATION

	needs_recipient_to_open = yes

	populate_actor_list = {
		scope:recipient = {
			every_courtier = {
				limit = {
					is_physically_able_adult = yes
					is_ruler = no
					could_marry_character_trigger = { CHARACTER = scope:actor }
					can_be_taken_as_muslim_concubine_trigger = {  # Can a Muslim be taken as concubine?
						CHARACTER = scope:actor 
						RECEIVER = scope:actor
					}
				}
				add_to_list = characters
			}
		}
	}

	is_shown = {
		scope:actor != scope:recipient
		scope:actor = {
			allowed_concubines = yes
		}
		scope:recipient = {
			OR = {
				trigger_if = {
					limit = {
						scope:actor = {
							government_has_flag = government_is_nomadic
						}
					}
					is_vassal_of = scope:actor
				}
				is_tributary_of = scope:actor
			}
		}
	}

	is_valid_showing_failures_only = {
		scope:actor = {
			allowed_more_concubines = yes
			is_physically_able_adult = yes
		}
		custom_tooltip = {
			text = must_have_valid_concubine_tt
			scope:recipient = {
				any_courtier = {
					is_physically_able_adult = yes
					is_ruler = no
					could_marry_character_trigger = { CHARACTER = scope:actor }
					can_be_taken_as_muslim_concubine_trigger = {  # Can a Muslim be taken as concubine?
						CHARACTER = scope:actor 
						RECEIVER = scope:actor
					}
				}
			}
		}
	}

	can_be_picked = {
		is_adult = yes
	}

	can_send = {
	}

	auto_accept = no

	ai_accept = {
		base = 0
		
		modifier = {
			add = 1000
			scope:recipient = {
				is_obedient_to = scope:actor
			}
			desc = AI_OBEDIENT_REASON
		}
		
		modifier = {
			add = 25
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 1
				}
			}
			desc = INTIMIDATED_REASON
		}
		
		modifier = {
			add = 50
			scope:recipient = {
				has_dread_level_towards = {
					target = scope:actor
					level = 2
				}
			}
			desc = COWED_REASON
		}
		
		opinion_modifier = { # Opinion Factor
			who = scope:recipient
			opinion_target = scope:actor
			multiplier = 1.0
			desc = AI_OPINION_REASON
		}
		
		modifier = {
			add = -25
			scope:secondary_actor = {
				OR = {
					is_councillor = yes
					has_any_court_position = yes
				}
			}
			desc = AI_EMPLOYED_COURTIER_REASON
		}
		
		modifier = {
			add = -15
			scope:secondary_actor = {
				is_knight = yes
			}
			desc = AI_IS_KNIGHT_REASON
		}
		
		modifier = {
			add = -50
			exists = scope:secondary_actor.inspiration
			desc = AI_INSPIRED_REASON
		}
		
		modifier = {
			add = -25
			scope:secondary_actor = {
				is_close_or_extended_family_of = scope:recipient
			}
			desc = AI_FAMILY_REASON
		}
		
		modifier = {
			add = -50
			scope:secondary_actor = {
				has_relation_friend = scope:recipient
			}
			desc = AI_FRIEND_REASON
		}
		
		modifier = {
			add = -50
			scope:secondary_actor = {
				is_consort_of = scope:recipient
			}
			desc = AI_SPOUSE_REASON
		}
		
		modifier = {
			add = -50
			scope:secondary_actor = {
				is_child_of = scope:recipient
			}
			desc = AI_CHILD_REASON
		}
		
		modifier = {
			add = 1000
			scope:secondary_actor = {
				has_relation_rival = scope:recipient
			}
			desc = AI_RIVAL_REASON
		}

		# Harem Politics #
		modifier = {
			add = -100
			scope:secondary_actor = {
				NOT = {
					can_be_taken_as_muslim_concubine_trigger = {  # Can a Muslim be taken as concubine?
						CHARACTER = scope:recipient
						RECEIVER = scope:recipient
					}
				}
			}
			desc = AI_MUSLIM_REASON
		}
	}

	ai_potential = {
		OR = {
			has_trait = lustful
			ai_honor <= 0
		}
		any_tributary = { }
	}

	ai_will_do = {
		base = 0
		## Weight for personality.
		ai_value_modifier = {
			ai_boldness = 0.25
			ai_greed = 0.3
			ai_honor = -0.2
		}
		modifier = {
			add = 30
			scope:actor = {
				government_has_flag = government_is_nomadic
			}
			scope:recipient = {
				is_obedient_to = scope:actor
			}
		}
		modifier = {
			add = -80
			scope:actor = {
				government_has_flag = government_is_nomadic
			}
			scope:recipient = {
				NOT = {
					is_obedient_to = scope:actor
				}
			}
		}

		modifier = {
			add = 40
			scope:actor = {
				number_of_concubines < number_of_desired_concubines
			}
		}
		modifier = {
			add = -20
			scope:actor = {
				number_of_concubines >= number_of_desired_concubines
			}
		}

		#More/Less likely based on difference in rank between actor and recipient
		modifier = {
			add = 20
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 1
				}
			}
		}
		modifier = {
			add = 30
			scope:actor = {
				tier_difference = {
					target = scope:recipient
					value = 2
				}
			}
		}

		modifier = {
			add = 10
			scope:actor = {
				has_trait = lustful
			}
		}

		modifier = {
			add = -25
			scope:actor = {
				has_trait = celibate
			}
		}
		modifier = {
			add = -25
			scope:actor = {
				has_trait = chaste
			}
		}
		modifier = {
			add = -25
			scope:actor = {
				has_trait = forgiving
			}
		}
		modifier = {
			add = -25
			scope:actor = {
				has_trait = compassionate
			}
		}
		
		modifier = {
			add = 100
			scope:secondary_actor = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
					sum_of_all_skills_value >= sum_of_all_skills_threshold_good
					martial >= monumentally_high_skill_rating
					prowess >= extremely_high_skill_rating
					exists = inspiration
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_chancellor ?= { diplomacy < monumentally_high_skill_rating }
					}
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_steward ?= { stewardship < monumentally_high_skill_rating }
					}
					AND = {
						diplomacy >= monumentally_high_skill_rating
						scope:actor.cp:councillor_spymaster ?= { intrigue < monumentally_high_skill_rating }
					}
					has_conventionally_attractive_trigger = yes
					num_of_good_genetic_traits > 1
				}
			}
		}

		modifier = { #Virginity is prized
			add = -65
			scope:secondary_actor = {
				any_consort = {
					even_if_dead = yes
					count >= 1
				}
			}
		}
		
		modifier = {
			factor = 0
			scope:recipient = {
				OR = {
					has_relation_friend = scope:actor
					has_relation_best_friend = scope:actor
					has_relation_lover = scope:actor
					has_relation_soulmate = scope:actor
				}
			}
		}
		
		modifier = {
			factor = 0
			scope:secondary_actor = {
				OR = {
					has_conventionally_ugly_trigger = yes
					age >= 30
					is_visibly_fertile = no
				}
			}
		}
	}

	on_send = {
		scope:secondary_actor = { # to block the same character from being offered twice
			add_character_flag = {
				flag = has_been_offered_as_concubine
				days = 5
			}
		}
	}
	
	on_accept = {
		scope:recipient = {
			if = {
				limit = {
					scope:secondary_actor = {
						NOR = {
							is_consort_of = scope:recipient
							is_close_or_extended_family_of = scope:recipient
						}
					}
				}
				add_opinion = {
					target = scope:actor
					modifier = demanded_concubine_opinion
					opinion = -15
				}
			}
			else = {
				scope:secondary_actor = { save_scope_as = relationship_reason_involved_character }
				progress_towards_rival_effect = {
					REASON = rival_demanded_concubine
					CHARACTER = scope:actor
					OPINION = 0
				}
				add_opinion = {
					target = scope:actor
					modifier = demanded_concubine_opinion
					opinion = -50
				}
				clear_saved_scope = secondary_actor
			}
		}
		demand_concubine_interaction_on_accept_effect = yes
	}

	on_decline = {
		scope:actor = {
			send_interface_toast = {
				type = event_toast_effect_bad
				title = msg_concubine_demand_rejected_title
				right_icon = scope:recipient
				left_icon = scope:secondary_actor
				custom_tooltip = msg_courtier_demand_rejected
			}
		}
		scope:actor = {
			add_opinion = {
				target = scope:recipient
				modifier = upset_opinion
				opinion = -15
			}
		}
	}
}